#include "nrtypes.h"
#include "../synthesis/synthesis.h"

namespace testSynthesis
{
	void _testGcd(QWORD a, QWORD b, QWORD g)
	{
		QWORD c1, c2;
		gcd(a, b, &c1, &c2);
		assert(a * c1 + b * c2 == g);
	}

	void testGcd()
	{
		_testGcd(0, 0, 0);
		_testGcd(1, 0, 1);
		_testGcd(0, 1, 1);
		_testGcd(1, 1, 1);
		_testGcd(4, 9, 1);
		_testGcd(7, 13, 1);
		_testGcd(36, 45, 9);
	}

	void testGaloisField()
	{
		GaloisFieldPrime<2> GF2;
		assert(GF2.add(0, 0) == 0);
		assert(GF2.add(1, 0) == 1);
		assert(GF2.mult(0, 1) == 0);
		assert(GF2.add(1, 1) == 0);
		assert(GF2.inverse(1) == 1);

		GaloisFieldPrime<5> GF5;
		assert(GF5.add(4, 3) == 2);
		assert(GF5.mult(4, 3) == 2);
		assert(GF5.inverse(3) == 2);
		assert(GF5.inverse(2) == 3);
		assert(GF5.inverse(4) == 4);
	}

	void runtests()
	{
		testGcd();
		testGaloisField();
	}

}